import { renderIcon } from "../utils/CommonUtils";
import { Book } from "@vicons/ionicons5";

export class StateMoal {
  onGonging: Array<number>;
  finished: Array<number>;
  stopping: Array<number>;

  constructor(onGonging: Array<number>, finished: Array<number>, stopping: Array<number>) {
    this.onGonging = onGonging;
    this.finished = finished;
    this.stopping = stopping;
  }
  static getStateId(stateModel: StateMoal, state: string | undefined): Array<number> {
    //console.log(stateModel,state)
    if (stateModel === undefined) return [];
    if (state === "onGonging") return stateModel.onGonging;
    if (state === "finished") return stateModel.finished;
    if (state === "stopping") return stateModel.stopping;
    return [];
  }
  static getStateMap() {
    return [
      {
        label: "进行中",
        key: "onGonging",
        icon: renderIcon(Book),
      },
      {
        label: "未进行",
        key: "stopping",
        icon: renderIcon(Book),
      },
      {
        label: "已结束",
        key: "finished",
        icon: renderIcon(Book),
      },
    ];
  }
  static getStateMap4NewStage(toAdd: boolean) {
    if (toAdd)
      return [
        {
          label: "进行中",
          value: "onGonging",
        },
        {
          label: "未进行",
          value: "stopping",
        },
      ];
    else
      return [
        {
          label: "进行中",
          value: "onGonging",
        },
        {
          label: "未进行",
          value: "stopping",
        },
        {
          label: "已结束",
          value: "finished",
        },
      ];
  }
  static getStateCount(stateModel: StateMoal | undefined) {
    if (stateModel === undefined) return [];
    const showCountTag = [
      {
        name: "进行中",
        count: stateModel.onGonging.length,
      },
      {
        name: "未进行",
        count: stateModel.stopping.length,
      },
      {
        name: "已结束",
        count: stateModel.finished.length,
      },
    ];
    return showCountTag;
  }
  static getStateMap4Task() {
    return [
      {
        label: "进行中",
        key: "onGonging",
        icon: renderIcon(Book),
      },
      {
        label: "已结束",
        key: "finished",
        icon: renderIcon(Book),
      },
    ];
  }
  static getStateMap4NewTask() {
    return [
      {
        label: "进行中",
        value: "onGonging",
      },
      {
        label: "已结束",
        value: "finished",
      },
    ];
  }

  static getAllId(
    stateMoal: StateMoal | undefined,
    list: Set<number>,
    onGoing: boolean,
    stopping: boolean,
    finished: boolean,
  ) {
    if (stateMoal !== undefined) {
      if (onGoing)
        for (let i = 0; i < stateMoal.onGonging.length; i++) {
          list.add(stateMoal.onGonging[i]);
        }
      if (stopping)
        for (let i = 0; i < stateMoal.stopping.length; i++) {
          list.add(stateMoal.stopping[i]);
        }
      if (finished)
        for (let i = 0; i < stateMoal.finished.length; i++) {
          list.add(stateMoal.finished[i]);
        }
    }
  }

  static getLastStartTime(state: string) {
    if (state === "onGonging") return new Date().getTime();
    else return 0;
  }
  static deleteId(stateMoal: StateMoal, id: number | undefined, state: string) {
    if (stateMoal !== undefined && id !== undefined) {
      // console.log(stateMoal);
      if (state === "onGonging") stateMoal.onGonging = stateMoal.onGonging.filter(item => item !== id);
      if (state === "finished") stateMoal.finished = stateMoal.finished.filter(item => item !== id);
      if (state === "stopping") stateMoal.stopping = stateMoal.stopping.filter(item => item !== id);
    }
  }
  static addId(stateMoal: StateMoal, id: number, state: string) {
    if (stateMoal !== undefined && id !== undefined) {
      if (state === "onGonging") stateMoal.onGonging.push(id);
      if (state === "finished") stateMoal.finished.push(id);
      if (state === "stopping") stateMoal.stopping.push(id);
    }
  }
  static changeIdState(stateMoal: StateMoal, id: number, oldState: string, newState: string) {
    // console.log(stateMoal, id, oldState, newState);
    if (stateMoal !== undefined) {
      StateMoal.deleteId(stateMoal, id, oldState);
      StateMoal.addId(stateMoal, id, newState);
    }
  }
}
